﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using AppPriceLive.Entities.Models;
using AppPriceLive.Entities.Utils;
using AppPriceLive.Common;

namespace AppPriceLive.DAL.Base
{
    public class VCurrencyListInfoDAOBase
    {
        #region Fields

        protected string connectionStringName;

        #endregion

        #region Constructors

		public VCurrencyListInfoDAOBase(string connectionStringName)
		{
			this.connectionStringName = connectionStringName;
		}

		#endregion

        #region Methods

        /// <summary>
        /// Selects a single record from the VCurrencyListInfo view.
        /// </summary>
        public virtual VCurrencyListInfoInfo VCurrencyListInfoSelectWithCurrenListId(int? currenListId)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@CurrenListId", currenListId)
			};

            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "VCurrencyListInfoInfo_Select_With_CurrenListId", parameters))
            {
                if (dataReader.Read())
                {
                    return MakeVCurrencyListInfoInfo(dataReader);
                }
                else
                {
                    return null;
                }
            }
        }

        /// <summary>
        /// Selects group records from the VCurrencyListInfo view.
        /// </summary>
        public List<VCurrencyListInfoInfo> VCurrencyListInfoSelectWithCurrencyGroupId(int? currencyGroupId)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@CurrencyGroupId", currencyGroupId)
			};

            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "VCurrencyListInfoInfo_Select_With_CurrencyGroupId", parameters))
            {
                List<VCurrencyListInfoInfo> vCurrencyListInfoInfo = new List<VCurrencyListInfoInfo>();
                while (dataReader.Read())
                {
                    vCurrencyListInfoInfo.Add(MakeVCurrencyListInfoInfo(dataReader));
                }

                return vCurrencyListInfoInfo;
            }
        }

        /// <summary>
        /// Selects all records from the VCurrencyListInfo view.
        /// </summary>
        public List<VCurrencyListInfoInfo> VCurrencyListInfoSelectAll()
        {
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "VCurrencyListInfo_SelectAll"))
            {
                List<VCurrencyListInfoInfo> vCurrencyListInfoInfo = new List<VCurrencyListInfoInfo>();
                while (dataReader.Read())
                {
                    vCurrencyListInfoInfo.Add(MakeVCurrencyListInfoInfo(dataReader));
                }

                return vCurrencyListInfoInfo;
            }
        }

        /// <summary>
        /// Creates a new instance of the VCurrencyListInfo class and populates it with data from the specified SqlDataReader.
        /// </summary>
        protected virtual VCurrencyListInfoInfo MakeVCurrencyListInfoInfo(SqlDataReader dataReader)
        {
            VCurrencyListInfoInfo vCurrencyListInfoInfo =new VCurrencyListInfoInfo();
            vCurrencyListInfoInfo.CurrenListId = SqlClientUtility.GetInt32(dataReader, DbConstants.VCURRENCYLISTINFO.CURRENLISTID);
            vCurrencyListInfoInfo.CurrencyGroupId = SqlClientUtility.GetInt32(dataReader, DbConstants.VCURRENCYLISTINFO.CURRENCYGROUPID);
            vCurrencyListInfoInfo.VName = SqlClientUtility.GetString(dataReader, DbConstants.VCURRENCYLISTINFO.VNAME);
            vCurrencyListInfoInfo.EName = SqlClientUtility.GetString(dataReader, DbConstants.VCURRENCYLISTINFO.ENAME);
            vCurrencyListInfoInfo.OrderBy = SqlClientUtility.GetInt32(dataReader, DbConstants.VCURRENCYLISTINFO.ORDERBY);
            vCurrencyListInfoInfo.UpdateTime = SqlClientUtility.GetDateTime(dataReader, DbConstants.VCURRENCYLISTINFO.UPDATETIME);
            vCurrencyListInfoInfo.Bid = SqlClientUtility.GetDecimal(dataReader, DbConstants.VCURRENCYLISTINFO.BID);
            vCurrencyListInfoInfo.Ask = SqlClientUtility.GetDecimal(dataReader, DbConstants.VCURRENCYLISTINFO.ASK);
            vCurrencyListInfoInfo.UrlChart1Min = SqlClientUtility.GetString(dataReader, DbConstants.VCURRENCYLISTINFO.URLCHART1MIN);
            vCurrencyListInfoInfo.UrlChart10Min = SqlClientUtility.GetString(dataReader, DbConstants.VCURRENCYLISTINFO.URLCHART10MIN);
            vCurrencyListInfoInfo.UrlChart1Hour = SqlClientUtility.GetString(dataReader, DbConstants.VCURRENCYLISTINFO.URLCHART1HOUR);
            vCurrencyListInfoInfo.UrlChart1Day = SqlClientUtility.GetString(dataReader, DbConstants.VCURRENCYLISTINFO.URLCHART1DAY);
            vCurrencyListInfoInfo.UrlChart1Week = SqlClientUtility.GetString(dataReader, DbConstants.VCURRENCYLISTINFO.URLCHART1WEEK);
            vCurrencyListInfoInfo.UrlChart1Month = SqlClientUtility.GetString(dataReader, DbConstants.VCURRENCYLISTINFO.URLCHART1MONTH);
            vCurrencyListInfoInfo.UrlChart3Month = SqlClientUtility.GetString(dataReader, DbConstants.VCURRENCYLISTINFO.URLCHART3MONTH);
            vCurrencyListInfoInfo.UrlChart6Month = SqlClientUtility.GetString(dataReader, DbConstants.VCURRENCYLISTINFO.URLCHART6MONTH);
            vCurrencyListInfoInfo.UrlChart1Year = SqlClientUtility.GetString(dataReader, DbConstants.VCURRENCYLISTINFO.URLCHART1YEAR);

            return vCurrencyListInfoInfo;
        }

        #endregion
    }
}
